package com.buwstudio.api;

import java.security.Principal;
import java.util.Collections;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ResourceController {

	private String message = "Hello world!";

	@GetMapping(value = "/")
	public Map<String, String> home() {
		return Collections.singletonMap("message", message);
	}
	
	@GetMapping(value = "/hello")
	public String hello() {
		return "Hello resource";
	}

	@PostMapping(value = "/")
	public void updateMessage(@RequestBody String message) {
		this.message = message;
	}

	@GetMapping(value = "/user")
	public Map<String, String> user(Principal user) {
		return Collections.singletonMap("message", "user is: " + user.toString());
	}

}
